package com.xbongbong.saas.model;

import com.alibaba.fastjson.JSONArray;
import com.xbongbong.paas.pojo.dto.ChangeRuleStatusDTO;
import com.xbongbong.paas.toolbox.exception.XbbException;
import com.xbongbong.paas.toolbox.wrap.IModel;
import com.xbongbong.saas.domain.entity.PublicGroupSeniorEntity;
import com.xbongbong.sys.domain.entity.UserEntity;

import java.util.List;
import java.util.Map;

/**
 * @author zhouwq
 * 公海池高级模式分组
 * @date 2022/4/14 9:27
 */

public interface PublicGroupSeniorModel extends IModel<PublicGroupSeniorEntity> {

    @Override
    Integer insert(PublicGroupSeniorEntity entity) throws XbbException;

    /**
     * 批量插入
     */
    void insertBatch(List<PublicGroupSeniorEntity> publicGroupSeniorEntityLists);


        /**
         * 保存
         * @param entity 实体
         * @return
         * @throws
         */
    Integer save(PublicGroupSeniorEntity entity) throws XbbException;

    /**
     * 删除
     * @param key 主键
     * @param corpid 公司id
     * @return
     * @throws
     */
    Integer deleteByKey( Long key, String corpid);

    /**
     * 获取公海池分组
     * @param key 主键
     * @param corpid 公司id
     * @return
     * @throws
     *
     */
    PublicGroupSeniorEntity getByKey( Long key, String corpid);

    /**
     * 批量更新
     * @param list
     * @param corpid
     * @return
     */
    Integer updateBatch(List<PublicGroupSeniorEntity> list, String corpid);



    /**
     * 单条数据更新
     * @param publicGroup
     * @return
     */
    Integer update(PublicGroupSeniorEntity publicGroup);



    List<PublicGroupSeniorEntity> getByFormId (Long formId,String corpid,Integer del);

    /**
     * 查找指定条件，总数量
     * @param param 查询条件
     * @return
     */
    Integer getEntitysCount(Map<String ,Object>  param);

    /**
     * 最大的层级
     * @param formId
     * @param corpid
     * @return
     */
    Integer maxLevel(Long formId, String corpid);

    List<PublicGroupSeniorEntity> getByGroupName(String name, Long formId, String corpid,Integer status);

    /**
     * 获取公海分组树，根据sort排序
     * @param corpid
     * @param formId
     * @return
     * @throws XbbException
     */
    public JSONArray getGroupTree(String corpid, Long formId,Integer status) throws XbbException ;

    /**
     * 批量更新公海分组的状态
     * @param statusDTO
     * @return
     */
    Integer updateBatchStatus(ChangeRuleStatusDTO statusDTO) throws XbbException;

    /**
     * 初始化无分组
     * @param corpid，businessType，userId，formId
     * @return
     */
    PublicGroupSeniorEntity initNoPublicGroup(String corpid,Integer businessType, String userId,Long formId) throws XbbException;


    List<PublicGroupSeniorEntity> findEntitys(Map<String, Object> param);

    /**
     * 查询启用状态的公海分组列表
     * @param corpid
     * @param formId
     * @param status
     * @return
     */
    List<PublicGroupSeniorEntity> findEntityByStatus(String corpid,Long formId ,Integer status);


    /**
     * 批量逻辑删除
     * @param corpid
     * @param businessType
     * @return
     */
    Integer deleteByBusinessType(String corpid, Integer businessType) throws XbbException;


    List<PublicGroupSeniorEntity> filterGroupSeniorByUser(List<PublicGroupSeniorEntity> list, UserEntity userEntity);

    Map<Long, PublicGroupSeniorEntity> getPublicGroupMap(Long formId, String corpid);
}
